import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import {DICT_TYPE, getDictOptions,getIntDictOptions } from '@/utils/dict'

export const monitorTypeOpt = await getDictOptions(DICT_TYPE.MONITOR_TYPE)

// 表单校验
export const rules = reactive({
  webHookUrl: [{ required: true, message: 'webHookUrl不能为空', trigger: 'blur' }],
  name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
  functionName: [{ required: false, message: '功能类型不能为空', trigger: 'change' }],
})
let isMonitorType = false
// CrudSchema：https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '名称',
    field: 'name',
    isSearch: true,
    form: {
      componentProps: {
        maxlength:'20',
      }
    }
  },
  {
    label: 'WebHook地址',
    field: 'url',
    isSearch: false,
  },
  {
    label: '类型',
    field: 'type',
    isTable:false,
    isDetail: false,
    isForm:false,
    search:{
      hidden: false,
      value: 0
    }
  },
  {
    label: '是否监控日志',
    field: 'isTest',
    form: {
        component: 'Checkbox',
        componentProps: {
            options: [
                {
                  label: '是否监控日志（相关消息只推送至测试群）',
                },
            ]
        },
    },
  },
  {
    label: '功能类型',
    field: 'functionName',
    isSearch: false,
    isForm:false,
    isTable:false,
    formatter: (_: Recordable, __: TableColumn, cellValue: any) => { 
      let arr:any = []
      cellValue&&cellValue.split(',').forEach(item => {
        arr.push(monitorTypeOpt.find((account) => account.value === item)?.label)
      })
      return !arr.length?null:arr.join(',')
    },
    form: {
      colProps:{
        span:24
      },
      component: 'Checkbox',
      value:[],
      componentProps: {
          options: monitorTypeOpt
      }
    }
  },
  {
    label: '启用',
    field: 'isUse',
    dictType: DICT_TYPE.SYSTEM_MAIL_SEND_STATUS,
    isForm:false,
    isDetail: false,
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm:false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
